package com.easy.api.utils;

import com.easy.api.annotation.ApiMapping;
import com.easy.api.annotation.ApiProxy;
import org.apache.commons.lang3.StringUtils;

public class ApiUtils {


    public static String getRequestUrl(ApiProxy proxy, ApiMapping api) {
        String url = proxy.host();
        String path = api.value();
        StringBuilder sb = new StringBuilder(url);
        if (StringUtils.endsWith(url, "/")) {
            if (StringUtils.startsWith(path, "/")) {
                sb.append(path.substring(1, path.length()));
            } else {
                sb.append(path);
            }
        } else {
            if (StringUtils.startsWith(path, "/")) {
                sb.append(path);
            } else {
                sb.append("/").append(path);
            }
        }
        return sb.toString();

    }


}
